﻿<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="com.zaofan.bean.Admin"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
	String contextPath = request.getContextPath();
	Admin admin = (Admin)session.getAttribute("admin");
	if(admin == null){
		response.sendRedirect(contextPath + "/login.jsp?state=" + "session-invalid");
		return;
	}
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>文章修改</title>
<link href="<%=contextPath%>/admin/css/base.css" rel="stylesheet" />
<link href="<%=contextPath%>/admin/assets/css/bootstrap.min.css"
	rel="stylesheet" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/font-awesome.min.css" />
<!--[if IE 7]>
	<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/font-awesome-ie7.min.css" />
<![endif]-->
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/ace.min.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/ace-rtl.min.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/ace-skins.min.css" />
<!--[if lte IE 8]>
	<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace-ie.min.css" />
<![endif]-->
<script src="<%=contextPath%>/admin/assets/js/ace-extra.min.js"></script>
<!--[if lt IE 9]>
	<script src="<%=contextPath%>/admin/assets/js/html5shiv.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/jquery-ui-1.10.3.custom.min.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/bootstrap-timepicker.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/chosen.css" />
<link rel="stylesheet" href="<%=contextPath%>/admin/css/uploadify.css" />
<script src="<%=contextPath%>/admin/ckeditor/ckeditor.js"
	type="text/javascript"></script>
<link rel="stylesheet"
	href="<%=contextPath%>/admin/css/uploadify.css" />
<script type="text/javascript">  
       var contextPath='<%=contextPath%>';
       var action = '${action}';
</script>
</head>
<body style="background-color: #fff;">
	<div class="breadcrumbs" id="breadcrumbs">
		<script type="text/javascript">
			try {
				ace.settings.check('breadcrumbs', 'fixed')
			} catch (e) {
			}
		</script>
	</div>
	<div class="page-content">
		<!-- /.page-header -->
		<div class="row" style="height: 100%">
			<div class="col-xs-12">
				<div class="alert alert-info" role="alert">话题发布</div>
				<div class="popover-inner" style="">
					<div class="popover-content" id="" style="">
						<form class="form-horizontal" style="padding-top: 10px;"
							method="post" id="productForm">
							<input type="hidden" value="${topic.id }" name="id" />
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">标题：</label>
								<div class="col-sm-9">
									<input name="title" id="title" class="form-control"
										value="${topic.title }" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">简单描述：</label>
								<div class="col-sm-9">
									<input name="des" id="des" class="form-control"
										value="${topic.des }" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">文章内容：</label>
								<div class="col-sm-9 ">
									<textarea id="content" name="content" type="text"
										class="form-control" >${topic.content }</textarea>
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-2 control-label">类型：</label>
								<div class="col-sm-9 ">
									<input type="radio" name="type" value="1" <c:if test="${topic.type == 1}">checked="checked"</c:if> <c:if test="${action =='add'}">checked="checked"</c:if> />普通
									<input type="radio" name="type" value="2" <c:if test="${topic.type == 2}">checked="checked"</c:if> />精选
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>
							<div class="form-group" >
								<input type="hidden" value="${topic.image }" name="image" id="topImage" />
								<label for="" class="col-sm-2 control-label">图片：</label>
								<div class="col-sm-9">
									<div id="imageProduct"  <c:if test="${action !='update' }">
										style="display:none;"
									</c:if>>
										<img src="<%=contextPath %>${topic.image }" width="50" height="50" />
									</div>
									<br/>
									<input type="file" id="image" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>	
							<div class="form-group" >
								<input type="hidden" value="${topic.bigImage }" name="bigImage" id="topBigImage" />
								<label for="" class="col-sm-2 control-label">大图：</label>
								<div class="col-sm-9">
									<div id="imageBigProduct"  <c:if test="${action !='update' }">
										style="display:none;"
									</c:if>>
										<img src="<%=contextPath %>${topic.bigImage }" width="50" height="50" />
									</div>
									<br/>
									<input type="file" id="imageBig" />
								</div>
								<span class="input_tip" style="line-height: 30px;">*</span>
							</div>						
							
						</form>
					</div>
					<div class="popover-footer"
						style="overflow: hidden; text-align: center;">
						<button type="button" class="btn btn-primary"
							style="padding: 0px; margin: 0px 5px 5px 0px;" id="cancel">
							<i class="icon-ok"></i>取消
						</button>
						<button type="button" class="btn btn-danger"
							style="padding: 0px; margin: 0px 5px 5px 0px;" id="save">
							<i class="icon-edit"></i>保存
						</button>

					</div>
				</div>
			</div>
			<!-- /.col -->
		</div>
		<!-- /.row -->
	</div>
	<div id="loading"
		style="width: 32px; height: 32px; position: fixed; left: 40%; top: 40%; display: none;">
		<img src="<%=contextPath%>/admin/assets/css/images/loading.gif"
			width="32" height="32" />
	</div>
	<div class="popover"
		style="z-index: 9999; width: 150px; position: fixed; left: 40%; top: 40%;">
		<div class="arrow"></div>
		<div class="popover-inner">
			<h3 class="popover-title">操作提示</h3>
			<div class="popover-content" id="popover-content">
				<p>操作成功</p>
			</div>
		</div>
	</div>



	<script type="text/javascript">
		if ("ontouchend" in document)
			document
					.write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>"
							+ "<"+"/script>");
	</script>
	<script type="text/javascript">
		window.jQuery
				|| document
						.write("<script src='<%=contextPath%>/admin/assets/js/jquery-2.0.3.min.js'>"
								+ "<"+"script>");
	</script>

	<!--[if IE]>
		<script type="text/javascript">
			window.jQuery || document.write("<script src='<%=contextPath%>/admin/assets/js/jquery-1.10.2.min.js'>"+"<"+"script>");
		</script>
	<![endif]-->
	<script type="text/javascript">
		if ("ontouchend" in document)
			document
					.write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>"
							+ "<"+"script>");
	</script>
	<script src="<%=contextPath%>/admin/assets/js/bootstrap.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/typeahead-bs2.min.js"></script>

	<!--[if lte IE 8]>
		  <script src="assets/js/excanvas.min.js"></script>
	<![endif]-->
	<script
		src="<%=contextPath%>/admin/assets/js/jquery-ui-1.10.3.custom.min.js"></script>
	<script
		src="<%=contextPath%>/admin/assets/js/jquery.ui.touch-punch.min.js"></script>
	<script
		src="<%=contextPath%>/admin/assets/js/jquery.slimscroll.min.js"></script>
	<script
		src="<%=contextPath%>/admin/assets/js/jquery.easy-pie-chart.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.sparkline.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/ace-elements.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/ace.min.js"></script>
	<script src="<%=contextPath%>/admin/js/common.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery-form.js"></script>
	<script src="<%=contextPath%>/admin/js/jquery.uploadify.min.js"></script>
	<script	src="<%=contextPath%>/admin/assets/js/date-time/bootstrap-timepicker.min.js"></script>
	<script src="<%=contextPath%>/admin/js/jquery.uploadify.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.dataTables.bootstrap.js"></script>

	<script type="text/javascript">
		$("#save").bind("click", function() {
			if ($("#title").val() == "") {
				showMessage("请输入标题!!!");
				return;
			}
			if ($("#des").val() == "") {
				showMessage("请输入简单描述!!!");
				return;
			}
			if ($("#content").val() == "") {
				showMessage("请输入详细内容!!!");
				return;
			}
			if ($("#type").val() == "") {
				showMessage("请选择类型!!!");
				return;
			}
			if ($("#topImage").val() == "") {
				showMessage("请选择小图!!!");
				return;
			}
			if ($("#topBigImage").val() == "") {
				showMessage("请选择大图!!!");
				return;
			}
			$("#loading").show();
			$("#productForm").ajaxSubmit({
				type : "POST",
				url : contextPath + '/admin/topic?action=' + action,
				dataType : 'json',
				success : function(data) {
					if (data.success) {
						showMessage(data.msg);
						window.location.href='topic?action=list';
					} else {
						showMessage(data.msg);
					}
					$("#loading").hide();
				},
				error : function(msg) {
					$("#loading").hide();
					showMessage("操作失败");
				}
			});
		});

		$("#cancel").click(function() {
			history.back();

		});
		
		$("#image").uploadify({  
            'auto'           : true,  
            'swf'            : '<%=contextPath%>/admin/css/uploadify.swf',  
            'uploader'       : '<%=contextPath%>/upload?action=image',
            'queueID'        : 'tip',//与下面的id对应  
            'queueSizeLimit' :12,  
            'fileTypeDesc'   : '图片文件',  
            'fileTypeExts'   : '*.jpg;*.png', //控制可上传文件的扩展名，启用本项时需同时声明fileDesc  
            'multi'          : true,  
            'buttonText'     : '上传' ,
            onUploadSuccess : function(file, data,
					response) {
				if (response) {
					var json = eval("(" + data+ ")");
					var imgsrc = json.data;
					$("#topImage").val(imgsrc);
					$("#imageProduct").show();
					$("#imageProduct").find("img").attr("src",contextPath + imgsrc);
				}
			}
		});
		
		$("#imageBig").uploadify({  
            'auto'           : true,  
            'swf'            : '<%=contextPath%>/admin/css/uploadify.swf',  
            'uploader'       : '<%=contextPath%>/upload?action=image',
            'queueID'        : 'tip',//与下面的id对应  
            'queueSizeLimit' :12,  
            'fileTypeDesc'   : '图片文件',  
            'fileTypeExts'   : '*.jpg;*.png', //控制可上传文件的扩展名，启用本项时需同时声明fileDesc  
            'multi'          : true,  
            'buttonText'     : '上传' ,
            onUploadSuccess : function(file, data,
					response) {
				if (response) {
					var json = eval("(" + data+ ")");
					var imgsrc = json.data;
					$("#topBigImage").val(imgsrc);
					$("#imageBigProduct").show();
					$("#imageBigProduct").find("img").attr("src",contextPath + imgsrc);
				}
			}
		});
	</script>
</body>
</html>